﻿using Framework.Domain;
using Framework.Unity;

namespace Framework.Core
{
    public static class WorkItemExecutor
    {
        private static readonly IWorkItemExecutor AnotherWorkItemExecutor = Container.GetA<IWorkItemExecutor>();

        /// <summary>
        /// Executes an initialised WorkItem.
        /// </summary>
        /// <param name="workItem">The work item to execute.</param>
        /// <returns></returns>
        public static WorkItemExecutionResult Execute(IWorkItem workItem)
        {
            return AnotherWorkItemExecutor.Execute(workItem);
        }

        /// <summary>
        /// Initialises a WorkItem with a give Case.
        /// </summary>
        /// <param name="workItem"></param>
        /// <param name="caseId"></param>
        /// <returns></returns>
        public static WorkItemExecutionResult Execute(IWorkItem workItem, CaseId caseId)
        {
            return Execute(workItem, caseId, null);
        }

        /// <summary>
        /// Initialises a WorkItem with a give Case and subject.
        /// </summary>
        /// <param name="workItem"></param>
        /// <param name="caseId"></param>
        /// <param name="subject"></param>
        /// <returns></returns>
        public static WorkItemExecutionResult Execute(IWorkItem workItem, CaseId caseId, object subject)
        {
            workItem.InitializeCase(CaseLoader.Select(caseId));
            workItem.Subject = subject;
            return Execute(workItem);
        }
    }
}